package com.wtwd.device.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wtwd.device.dao.WebMedalMapper;
import com.wtwd.device.model.entity.Medal;
import com.wtwd.device.service.WebMedalService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zdl
 * @since 2022-04-11
 */
@Service
public class WebMedalServiceImpl implements WebMedalService {

    @Autowired
    private WebMedalMapper medalMapper;


    @Override
    public List<Medal> getMedalByType(Integer type) {
        return new LambdaQueryChainWrapper<>(medalMapper)
                .eq(Medal::getType,type)
                .list();

    }

    @Override
    public IPage queryMedalPageByCondition(Medal searchMap, Page<Medal> page) {
        return new LambdaQueryChainWrapper<>(medalMapper)
                .eq(Medal::getMedalTypeId,searchMap.getMedalTypeId())
                .like(StringUtils.isNotBlank(searchMap.getName()),Medal::getName,searchMap.getName())
                .page(page);
    }

    @Override
    public Integer addMedal(Medal medal) {
        return medalMapper.insert(medal);
    }

    @Override
    public Integer deleteMedalById(Long medalId) {
        return medalMapper.deleteById(medalId);
    }
}
